package com.liuweijiaoyu.demo.util;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 题目列表
 */
public class OnlineQuestion implements Serializable {

    private List<QuestionItem> mQuestionItems;
    private String res = "{\"code\":\"99999\",\"data\":[{\"questionId\":\"101\",\"questionNo\":1,\"questionType\":1,\"questionTypeName\":\"单选题\",\"content\":\"由大于-8小于20的奇数所组成的集合(　　)\",\"rightAnswer\":\"A\",\"answerExplain\":\"单选题解析\",\"answer\":\"A\",\"itemList\":[{\"itemCode\":\"A\",\"questionItem\":\"11\",\"isRight\":\"Y\"},{\"itemCode\":\"B\",\"questionItem\":\"12\",\"isRight\":\"N\"},{\"itemCode\":\"C\",\"questionItem\":\"13\",\"isRight\":\"N\"},{\"itemCode\":\"D\",\"questionItem\":\"14\",\"isRight\":\"N\"}]},{\"questionId\":\"102\",\"questionNo\":2,\"questionType\":2,\"questionTypeName\":\"多选题\",\"content\":\"由元素1，2，3组成的集合可记为(　　)\",\"rightAnswer\":\"AC\",\"answerExplain\":\"多选题解析\",\"answer\":\"AB\",\"itemList\":[{\"itemCode\":\"A\",\"questionItem\":\"11\",\"isRight\":\"Y\"},{\"itemCode\":\"B\",\"questionItem\":\"12\",\"isRight\":\"N\"},{\"itemCode\":\"C\",\"questionItem\":\"13\",\"isRight\":\"Y\"},{\"itemCode\":\"D\",\"questionItem\":\"14\",\"isRight\":\"N\"}]},{\"questionId\":\"103\",\"questionNo\":3,\"questionType\":4,\"questionTypeName\":\"解答题\",\"content\":\"<div class=\\\"math-panel\\\" style=\\\"visibility: visible;\\\"><div style=\\\"visibility: hidden; overflow: hidden; position: absolute; top: 0px; height: 1px; width: auto; padding: 0px; border: 0px; margin: 0px; text-align: left; text-indent: 0px; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal;\\\" id=\\\"FINISH_DRAW\\\"><svg><defs id=\\\"MathJax_SVG_glyphs\\\"><path stroke-width=\\\"1\\\" id=\\\"STIXWEBMAIN-3C\\\" d=\\\"M621 -24l-565 273v10l565 275v-65l-432 -215l432 -215v-63Z\\\"></path><path stroke-width=\\\"1\\\" id=\\\"STIXWEBMAIN-2265\\\" d=\\\"M629 324l-565 -273v63l432 215l-432 215v65l565 -275v-10zM629 -103h-565v66h565v-66Z\\\"></path><path stroke-width=\\\"1\\\" id=\\\"STIXWEBVARIANTS-2205\\\" d=\\\"M502 729l-77 -148c49 -77 65 -181 65 -251c0 -121 -42 -345 -226 -345c-51 0 -91 19 -123 48l-56 -107h-57l77 149c-50 75 -67 180 -67 255c0 118 42 345 226 345c37 0 68 -9 94 -25c12 -7 22 -16 32 -26l55 105h57zM147 155l213 411c-19 48 -48 83 -96 83 c-92 0 -130 -134 -130 -319c0 -53 2 -118 13 -175zM380 493l-212 -409c19 -43 49 -73 96 -73c128 0 130 240 130 319c0 31 -2 98 -14 163Z\\\"></path></defs></svg></div><p style=\\\"\\\"><span style=\\\"\\\">(1)</span>已知集合<span style=\\\"\\\"><em>A</em></span><span style=\\\"\\\">={x</span><span style=\\\"\\\">∣</span><span style=\\\"\\\">2x-3<kb:math class=\\\"math-latxt\\\" xmlns:kb=\\\"http://www.knowbox.cn/\\\"><svg xmlns:xlink=\\\"http://www.w3.org/1999/xlink\\\" width=\\\"1.592ex\\\" height=\\\"1.676ex\\\" viewBox=\\\"0 -623.9 685.5 721.6\\\" role=\\\"img\\\" focusable=\\\"false\\\" style=\\\"vertical-align: -0.227ex;\\\"><g stroke=\\\"currentColor\\\" fill=\\\"currentColor\\\" stroke-width=\\\"0\\\" transform=\\\"matrix(1 0 0 -1 0 0)\\\"><use xlink:href=\\\"#STIXWEBMAIN-3C\\\" x=\\\"0\\\" y=\\\"0\\\"></use></g></svg></kb:math>3x}</span>，B<span style=\\\"\\\">={x</span><span style=\\\"\\\">∣</span><span style=\\\"\\\">x<kb:math class=\\\"math-latxt\\\" xmlns:kb=\\\"http://www.knowbox.cn/\\\"><svg xmlns:xlink=\\\"http://www.w3.org/1999/xlink\\\" width=\\\"1.592ex\\\" height=\\\"2.009ex\\\" viewBox=\\\"0 -671.8 685.5 865.1\\\" role=\\\"img\\\" focusable=\\\"false\\\" style=\\\"vertical-align: -0.449ex;\\\"><g stroke=\\\"currentColor\\\" fill=\\\"currentColor\\\" stroke-width=\\\"0\\\" transform=\\\"matrix(1 0 0 -1 0 0)\\\"><use xlink:href=\\\"#STIXWEBMAIN-2265\\\" x=\\\"0\\\" y=\\\"0\\\"></use></g></svg></kb:math>2}</span>则有：</p><p style=\\\"\\\"><span style=\\\"\\\">-4&nbsp;<span style=\\\"text-decoration:underline;\\\">&nbsp;</span><span style=\\\"text-decoration:underline;\\\">&nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp;<em>B</em></span>；<span style=\\\"\\\">&nbsp;&nbsp;&nbsp;&nbsp;-3&nbsp;<span style=\\\"text-decoration:underline;\\\">&nbsp;</span><span style=\\\"text-decoration:underline;\\\">&nbsp; &nbsp; &nbsp; &nbsp;</span>&nbsp;<em>A</em></span>；<span style=\\\"\\\">&nbsp;&nbsp;&nbsp;&nbsp;{2}&nbsp;<span style=\\\"text-decoration:underline;\\\">&nbsp;</span><span style=\\\"text-decoration:underline;\\\">&nbsp; &nbsp; &nbsp;</span>&nbsp;<em>B</em></span>；<span style=\\\"\\\">&nbsp;&nbsp;&nbsp;&nbsp;B&nbsp;<span style=\\\"text-decoration:underline;\\\">&nbsp;</span><span style=\\\"text-decoration:underline;\\\">&nbsp; &nbsp; &nbsp; &nbsp;</span> <em>A</em>；</span></p><p style=\\\"\\\"><span style=\\\"\\\">(2)已知集合<span style=\\\"\\\"><em>A</em></span><span style=\\\"\\\">={x</span><span style=\\\"\\\">∣x<sup>2</sup>-1=0</span><span style=\\\"\\\">},则有；</span></span></p><p style=\\\"\\\"><span style=\\\"\\\">1 &nbsp;<span style=\\\" text-decoration: underline;\\\"> &nbsp; &nbsp; &nbsp; &nbsp;</span><span style=\\\"\\\"><span style=\\\" text-decoration: none;\\\"> <em>A</em>；&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span style=\\\"\\\">{-1}</span><span style=\\\" text-decoration: underline;\\\"></span><span style=\\\" text-decoration: underline;\\\">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=\\\"\\\">&nbsp;<em>A</em>；</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<kb:math class=\\\"math-latxt\\\" xmlns:kb=\\\"http://www.knowbox.cn/\\\"><svg xmlns:xlink=\\\"http://www.w3.org/1999/xlink\\\" width=\\\"1.216ex\\\" height=\\\"2.232ex\\\" viewBox=\\\"0 -815.3 523.5 960.8\\\" role=\\\"img\\\" focusable=\\\"false\\\" style=\\\"vertical-align: -0.338ex;\\\"><g stroke=\\\"currentColor\\\" fill=\\\"currentColor\\\" stroke-width=\\\"0\\\" transform=\\\"matrix(1 0 0 -1 0 0)\\\"><use xlink:href=\\\"#STIXWEBVARIANTS-2205\\\" x=\\\"0\\\" y=\\\"0\\\"></use></g></svg></kb:math>&nbsp;<span style=\\\" text-decoration: underline;\\\">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=\\\"\\\">&nbsp;<em>A</em>；</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<span style=\\\"\\\">{1.-1}</span><span style=\\\" text-decoration: underline;\\\">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=\\\"\\\">&nbsp;<em>A</em>；</span></span></span></span></p><p style=\\\"\\\"><span style=\\\"\\\">(3)</span><span style=\\\"\\\">{<span style=\\\"\\\">x</span><span style=\\\"\\\">∣</span>x</span><span style=\\\"\\\"><span style=\\\"\\\">是菱形</span></span><span style=\\\"\\\">}&nbsp;<span style=\\\" text-decoration: underline;\\\">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style=\\\"\\\"><span style=\\\" text-decoration: none;\\\">&nbsp;<span style=\\\"\\\">{x</span><span style=\\\"\\\">∣</span><span style=\\\"\\\">x是平行四边形}</span></span></span></span></p><p style=\\\"\\\"><span style=\\\"\\\"><span style=\\\"text-decoration: none;\\\"><span style=\\\"\\\">{x</span><span style=\\\"\\\">∣x是等腰三角形</span><span style=\\\"\\\">}&nbsp;</span></span><span style=\\\"\\\"><span style=\\\" text-decoration: underline;\\\"> &nbsp; &nbsp; &nbsp; &nbsp;</span><span style=\\\"\\\"><span style=\\\" text-decoration: none;\\\">&nbsp;<span style=\\\"\\\">{x</span><span style=\\\"\\\">∣</span><span style=\\\"\\\">x是等边三角形}</span></span></span></span></span></p><p style=\\\"\\\"><br></p><p style=\\\"\\\"><span style=\\\"\\\"><br></span></p></div></br><img alt='图1' src='http://img.jyeoo.net/quiz/images/201706/59/b05f1134.png' /> <img alt='图2' src='http://img.jyeoo.net/quiz/images/201706/62/dda05712.png' /> \",\"rightAnswer\":\"\",\"answerExplain\":\"习题解析</br><span style=\\\"ll_fenxi\\\">[分析]</span><br/> <span class=\\\"uc_q_object\\\">首先对已知函数进行化简，根据在(-2，2)内为增函数判断出a的取值范围．</span>     <br/><span style=\\\"ll_jieda\\\">[解答]</span><br/> <span class=\\\"uc_q_object\\\">解：∵f(x)=</span><div class=\\\"uc_q_object uc_q_fraction\\\"><div class=\\\"ucqo_frac\\\"><table class=\\\"ucqo_frac_frac\\\"><tr><td class=\\\"ucqo_frac_numerator\\\">ax+1</td></tr><tr><td class=\\\"ucqo_frac_denominator ucqo_g_border\\\">x+2</td></tr></table></div></div><span class=\\\"uc_q_object\\\">(a为常数)，<br>而</span><div class=\\\"uc_q_object uc_q_fraction\\\"><div class=\\\"ucqo_frac\\\"><table class=\\\"ucqo_frac_frac\\\"><tr><td class=\\\"ucqo_frac_numerator\\\">ax+1</td></tr><tr><td class=\\\"ucqo_frac_denominator ucqo_g_border\\\">x+2</td></tr></table></div></div><span class=\\\"uc_q_object\\\">=</span><div class=\\\"uc_q_object uc_q_fraction\\\"><div class=\\\"ucqo_frac\\\"><table class=\\\"ucqo_frac_frac\\\"><tr><td class=\\\"ucqo_frac_numerator\\\">a(x+2)-2a+1</td></tr><tr><td class=\\\"ucqo_frac_denominator ucqo_g_border\\\">x+2</td></tr></table></div></div><span class=\\\"uc_q_object\\\">=a+</span><div class=\\\"uc_q_object uc_q_fraction\\\"><div class=\\\"ucqo_frac\\\"><table class=\\\"ucqo_frac_frac\\\"><tr><td class=\\\"ucqo_frac_numerator\\\">-2a+1</td></tr><tr><td class=\\\"ucqo_frac_denominator ucqo_g_border\\\">x+2</td></tr></table></div></div><span class=\\\"uc_q_object\\\"><br>∵f(x)在(-2，2)内为增函数<br>而x+2为增函数，</span><div class=\\\"uc_q_object uc_q_fraction\\\"><div class=\\\"ucqo_frac\\\"><table class=\\\"ucqo_frac_frac\\\"><tr><td class=\\\"ucqo_frac_numerator\\\">1</td></tr><tr><td class=\\\"ucqo_frac_denominator ucqo_g_border\\\">x+2</td></tr></table></div></div><span class=\\\"uc_q_object\\\">为减函数<br>∴要使f(x)在(-2，2)内为增函数<br>∴-2a+1＜0<br>解得：a＞</span><div class=\\\"uc_q_object uc_q_fraction\\\"><div class=\\\"ucqo_frac\\\"><table class=\\\"ucqo_frac_frac\\\"><tr><td class=\\\"ucqo_frac_numerator\\\">1</td></tr><tr><td class=\\\"ucqo_frac_denominator ucqo_g_border\\\">2</td></tr></table></div></div><span class=\\\"uc_q_object\\\"><br>故答案为：C</span>     <br/><span style=\\\"ll_dianping\\\">[点评]</span><br/> <span class=\\\"uc_q_object\\\">本题考查函数单调性的应用，通过对函数的分析，判断各部分的单调性，属于中档题．</span>     <br/>\",\"answer\":\"  \"}]}";

    public List<QuestionItem> parse() {
        try {
            JSONObject json = new JSONObject(res);

            mQuestionItems = new ArrayList<>();
            JSONArray jsonAsrr = json.getJSONArray("data");
            QuestionItem tempQuestionBean;
            QuestionSubItem tempQuestionSubBean;
            List<QuestionSubItem> tempQuestionSubItems;
            for (int i = 0; i < jsonAsrr.length(); i++) {
                JSONObject questionObj = jsonAsrr.getJSONObject(i);
                tempQuestionBean = new QuestionItem();
                tempQuestionBean.setQuestionId(questionObj.optString("questionId"));
                tempQuestionBean.setQuestionNO(questionObj.optString("questionNo"));
                tempQuestionBean.setQuestionType(questionObj.optInt("questionType"));
                tempQuestionBean.setQuestionTypeName(questionObj.optString("questionTypeName"));
                tempQuestionBean.setContent(questionObj.optString("content"));
                tempQuestionBean.setRightAnswer(questionObj.optString("rightAnswer"));
                tempQuestionBean.setAnswerExplain(questionObj.optString("answerExplain"));

                if (questionObj.has("answer")) {
                    tempQuestionBean.setAnswer(questionObj.optString("answer"));
                }
                if (questionObj.has("itemList")) {
                    tempQuestionSubItems = new ArrayList<>();
                    JSONArray questionSubArr = questionObj.optJSONArray("itemList");
                    for (int j = 0; j < questionSubArr.length(); j++) {
                        tempQuestionSubBean = new QuestionSubItem();
                        JSONObject questionSubObj = questionSubArr.getJSONObject(j);
                        tempQuestionSubBean.setItemCode(questionSubObj.optString("itemCode"));
                        tempQuestionSubBean.setIsRight(questionSubObj.optString("isRight"));
                        tempQuestionSubBean.setQuestionItem(questionSubObj.optString("questionItem"));
                        tempQuestionSubItems.add(tempQuestionSubBean);
                    }
                    tempQuestionBean.setQuestionSubItemList(tempQuestionSubItems);
                }
                mQuestionItems.add(tempQuestionBean);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return mQuestionItems;
    }

    public static class QuestionItem implements Serializable {
        private String questionId;//题目id
        private String questionNO;//题号
        private int questionType;//题型
        private String questionTypeName;//题型
        private String content;//题干
        private String answer;//答案
        private String rightAnswer;//正确答案
        private String answerExplain;//解析


        private List<QuestionSubItem> questionSubItemList;//选择题的选项

        public String getQuestionId() {
            return questionId;
        }

        public void setQuestionId(String questionId) {
            this.questionId = questionId;
        }

        public String getQuestionTypeName() {
            return questionTypeName;
        }

        public void setQuestionTypeName(String questionTypeName) {
            this.questionTypeName = questionTypeName;
        }

        public String getQuestionNO() {
            return questionNO;
        }

        public void setQuestionNO(String questionNO) {
            this.questionNO = questionNO;
        }

        public int getQuestionType() {
            return questionType;
        }

        public void setQuestionType(int questionType) {
            this.questionType = questionType;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getRightAnswer() {
            return rightAnswer;
        }

        public void setRightAnswer(String rightAnswer) {
            this.rightAnswer = rightAnswer;
        }

        public String getAnswerExplain() {
            return answerExplain;
        }

        public void setAnswerExplain(String answerExplain) {
            this.answerExplain = answerExplain;
        }

        public String getAnswer() {
            return answer;
        }

        public void setAnswer(String answer) {
            this.answer = answer;
        }


        public List<QuestionSubItem> getQuestionSubItemList() {
            return questionSubItemList;
        }

        public void setQuestionSubItemList(List<QuestionSubItem> questionSubItemList) {
            this.questionSubItemList = questionSubItemList;
        }
    }

    public static class QuestionSubItem implements Serializable {

        private String itemCode;//选项标识
        private String questionItem;//选项内容
        private String isRight;//是否正确

        public String getItemCode() {
            return itemCode;
        }

        public void setItemCode(String itemCode) {
            this.itemCode = itemCode;
        }

        public String getQuestionItem() {
            return questionItem;
        }

        public void setQuestionItem(String questionItem) {
            this.questionItem = questionItem;
        }

        public String getIsRight() {
            return isRight;
        }

        public void setIsRight(String isRight) {
            this.isRight = isRight;
        }
    }
}
